<?php
require( 'util.php' );
require('dbconnect.php');
require('Stencil.php');
output_frame_header('资料下载');
?>
	<div class="space"></div>
	<!-- 内容板块 -->
<div>
<?php // display the files uploaded to the server
 $page_title='View Files';
 
 
 $first=TRUE;

 $query="SELECT * FROM uploads";
 $result=mysql_query($query);
 $num=mysql_num_rows($result);
 $pagesize=4;
 $pagemax=ceil($num/$pagesize);
 if(isset($_GET['page'])){
    $page=intval($_GET['page']);
 }else{
       $page=1;
 }
 
 $back=$page-1;
 $next=$page+1;
 $start=($page-1)*$pagesize;

 $query="SELECT upload_id, file_name, ROUND(file_size/1024) AS fs, description,
		DATE_FORMAT(date_entered, '%M %e, %Y') AS d FROM uploads 
		ORDER BY date_entered DESC limit " . $start . "," . $pagesize;
 $result=mysql_query($query);

 //display
 while ($row=mysql_fetch_array($result, MYSQL_ASSOC)) {
  if ( isset( $_SESSION['u_id'] ) && ($_SESSION['group']=='M')) {
	if ($first) {
		echo '<table border="0" width="1000" cellspacing="3" cellpadding="0" align="center" style="font-size:12pt">
				<tr style="font-size:12pt">
					<td align="left" width=200><b>文件名字</b></td>
					<td align="left" width=500><b>文件描述</b></td>
					<td align="center" width=100><b>文件大小</b></td>
					<td align="center" width=150><b>上传时间</b></td>
					<td align=right" width=50></td>
				</tr>';
		$first = FALSE;
	}
	echo " <tr style='font-size:11pt'>
				<td align=\"left\"><a href=\"download_file.php?f_id={$row['upload_id']}\">{$row['file_name']}</a></td>
				<td align=\"left\">{$row['description']}</td>
				<td align=\"center\">{$row['fs']}kb</td>
				<td align=\"center\">{$row['d']}</td>
				<td align=\"right\"><a href=\"delete_file.php?f_id={$row['upload_id']}\" onclick=\"return confirm('删除后无法恢复,确定要删除吗')\">删除</a></td>
		   </tr>\n";
  } else {
	  if ($first) {
		echo '<table border="0" width="1000" cellspacing="3" cellpadding="0" align="center" >
				<tr style="font-size:12pt">
					<td align="left" width=200><b>文件名字</b></td>
					<td align="left" width=500><b>文件描述</b></td>
					<td align="center" width=100><b>文件大小</b></td>
					<td align="center" width=150><b>上传时间</b></td>
				</tr>';
		$first = FALSE;
	  }
	echo " <tr style='font-size:11pt'>
				<td align=\"left\"><a href=\"download_file.php?f_id={$row['upload_id']}\">{$row['file_name']}</a></td>
				<td align=\"left\">{$row['description']}</td>
				<td align=\"center\">{$row['fs']}kb</td>
				<td align=\"center\">{$row['d']}</td>
		   </tr>\n";
	}
}

if ($first) {
	echo '<div align="center" style="font-size:12pt"><b>--目前没有可用资料--</b></div>';
} else {
	echo '</table>';
}

mysql_close();
?>
	<div id="page"> 
	<?php
    if($pagemax!=1){
	?>
		<table border="0" width="1000" cellspacing="3" cellpadding="0" align="center" style="font-size:11pt">
			<tr>
					<?php 
					if ($page>1) 
					echo "<td align=\"right\" width=720><a href=\"?page=1\">首页</a></td>
						  <td align=\"right\" width=60><a href=\"?page=$back\">上一页</a></td>";
					else echo "<td align=\"right\" width=720><b>首页</b></td>
							   <td align=\"right\" width=60><b>上一页</b></td>";
					if ($page<$pagemax) 
					echo "<td align=\"right\" width=80><a href=\"?page=$next\">下一页</a></td>
						  <td align=\"right\" width=40><a href=\"?page=$pagemax\">尾页</a></td>";
					else echo "<td align=\"right\" width=80><b>下一页</b></td>
							   <td align=\"right\" width=40><b>尾页</b></td>"; 
					echo "<td align=\"right\" width=50><b>第{$page}页</b></td>
					      &nbsp;
						  <td align=\"right\" width=50><b>共{$pagemax}页</b></td>";
					?>
			</tr>
		</table>
	<?php
	}
	?>
     </div>
</div>
&nbsp;
<?
if ( isset( $_SESSION['u_id'] ) && ($_SESSION['group']=='M') )
echo <<<ROD
<div>
<table width=1000 align=center>
<form enctype="multipart/form-data" action="add_file.php" method="post">
	<div><fieldset><legend><b>
	<font style="font-size:12pt">-----------------------------------上传文件-----------------------------------</font></b></legend>
	<p><b>文件路径:</b><input type="file" name="upload" /></p>
	<p><b>文件描述:</b><textarea name="description" cols="40" rows='5'></textarea></p></fieldset></div>
	<input type="hidden" name="submitted" value="TRUE" />
	<div align="center"><input type="submit" name="submit" value="上传"></div>
</form>
</table>
</div>
ROD
?>
<div class="space"></div>
<?php output_frame_footer(); ?>